﻿<?php
include("mysql.php");

$image_id = $_POST['id'];
$message = $_POST['message'];

$query = sprintf("INSERT INTO messages (img_id,text) VALUES ('%s','%s')",
mysql_real_escape_string($image_id),mysql_real_escape_string($message));
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
	$message  = 'Invalid query: ' . mysql_error() . "\n";
	$message .= 'Whole query: ' . $query;
	print(json_encode("FEEDBACK_START"));
	$output = "There was an error sending the message, please try again!";
	$output = "FEEDBACK_KEY_UPLOAD".$output;
	print(json_encode($output));
	die($message);
}


print(json_encode("FEEDBACK_START"));
$output = "Your message has been sent";
$output = "FEEDBACK_KEY_MESSAGE".$output;
print(json_encode($output));
$ukey = mysql_insert_id();
$output = "FEEDBACK_KEY_ID".$ukey;
print(json_encode($output));
mysql_close();
?>